package Client;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;

import org.feiteira.network.copy.SeriDataPackage;
import org.feiteira.network.copy.SeriEventHandler;

import NET.NetPlayer;

public class ClientEventHandler implements SeriEventHandler {

   @Override
   public void messageArrived(SeriDataPackage pack) {
      Serializable fromServer = pack.getObject();
      if(fromServer instanceof ArrayList<?>) {
         for(Object o: (ArrayList<?>)fromServer) {
            if(o instanceof NetPlayer) {
               NetPlayer np = (NetPlayer) o;
               System.out.println("Server: " + np.toString());
            }
         }
      }
      if(fromServer instanceof String) {
         if(fromServer.equals("Bye.")) {
            try {
               pack.getSocket().close();
            } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
         }
      }
   }

   @Override
   public void shutdownCompleted() {
      // TODO Auto-generated method stub

   }

}
